package com.spleeb.pixelengine;


public class LineModel implements ModelData {
	public float[] data;
	public int color;
	public int lwidth = 1;
	public LineModel(int[] cords,int color){
		init(cords,color);
	}
	public LineModel(int[] cords,int color,int lwidth){
		this.lwidth = lwidth;
		init(cords,color);
	}
	public void init(int[] cords,int color){
		this.color = color;
		data = new float[cords.length];
		for (int i = 0;i<cords.length;i+=2){
			data[i] = GameMath.sqrt(cords[i]*cords[i] + cords[i+1] * cords[i+1]);
			data[i+1] = (float)Math.atan2(cords[i+1], cords[i]);
		}
	}
	public void Draw(Screen screen, Satrix matrix) {
		// TODO Auto-generated method stub
		float[] act = new float[data.length];
		for (int i = 0;i<act.length;i+=2){
			act[i] = matrix.x + GameMath.cos(data[i+1]+matrix.rot) * data[i] * matrix.sx;
			act[i+1] = matrix.y + GameMath.sin(data[i+1]+matrix.rot) * data[i] * matrix.sy;
		}
		for (int i = 2;i<act.length;i+=2){
			float a = act[i] - act[i-2];
			float b = act[i+1] - act[i-1];
			int dis = GameMath.ceil(GameMath.sqrt(a*a+b*b));
			float xp = a/dis;
			float yp = b/dis;
			for (int u = 0;u<dis;u++){
				float npx = act[i-2]+ xp * u;
				float npy = act[i-1] + yp*u;
				for (float w = lwidth/-2;w<lwidth/2;w++){
					screen.set(npx + w*yp, npy + w*-1*xp, color);
				}
			}
		}
	}

}
